package com.huatai.manage.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.huatai.common.api.R;
import com.huatai.manage.query.PageQuery;
import com.huatai.manage.query.RemoveQuery;
import com.huatai.manage.entity.TbTrialInfoEntity;
import com.huatai.manage.service.TbTrialInfoService;
import com.huatai.manage.utils.ComUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * (TbTrialInfo)表控制层
 *
 * @author luoxc
 * @since 2023-03-14 14:13:39
 */
@RestController
@RequestMapping("info")
@Api(value = "试验基本信息", tags = "试验基本信息")
public class TbTrialInfoController {

	@Autowired
	private TbTrialInfoService tbTrialInfoService;

	@ApiOperationSupport(order = 1, includeParameters = {
		"pageQuery.current",
		"pageQuery.size",
		"pageQuery.data.trialName",
		"pageQuery.data.trialType"
	})
	@PostMapping("pageList")
	@ApiOperation(value = "分页查询", notes = "分页查询")
	public R pageList(@RequestBody PageQuery<TbTrialInfoEntity> pageQuery) {
		return R.data(this.tbTrialInfoService.pageList(pageQuery));
	}

	@GetMapping("selectList")
	@ApiOperation(value = "查询所有数据", notes = "查询所有数据")
	public R list() {
		return R.data(this.tbTrialInfoService.trialList());
	}


	@PostMapping("getByTrialId")
	@ApiOperation(value = "通过试验id查询单条数据", notes = "通过试验id查询单条数据")
	public R getOne(@ApiParam(name = "trialId",value = "试验id", required = true) @RequestParam("trialId") String trialId) {
		return R.data(this.tbTrialInfoService.getByTrialId(trialId));
	}


	@PostMapping("insert")
	@ApiOperation(value = "新增数据", notes = "新增数据")
	public R insert(@RequestBody @Valid TbTrialInfoEntity tbTrialInfoEntity) {
		return R.status(this.tbTrialInfoService.save(tbTrialInfoEntity.setTrialId(ComUtil.getUUID())));
	}


	@PostMapping("update")
	@ApiOperation(value = "修改数据", notes = "修改数据")
	public R update(@RequestBody @Valid TbTrialInfoEntity tbTrialInfoEntity) {
		return R.status(this.tbTrialInfoService.update(tbTrialInfoEntity));
	}


	@PostMapping("removes")
	@ApiOperation(value = "删除数据", notes = "删除数据")
	public R removes(@RequestBody RemoveQuery remove) {
		return R.status(this.tbTrialInfoService.removes(remove.getIds()));
	}

	@PostMapping("isExist")
	@ApiOperation(value = "trialId是否存在", notes = "trialId是否存在")
	public R isExist(@ApiParam(name = "trialId",value = "试验id", required = true) @RequestParam("trialId") String trialId) {
		return R.data(tbTrialInfoService.isExist(trialId));
	}
}

